package com.example.shirodemo.controller;

import com.example.shirodemo.config.ShiroConfig;
import com.example.shirodemo.config.custom.CustomShiroCache;
import com.example.shirodemo.constant.HttpCode;
import com.example.shirodemo.dto.ResponseResult;
import com.example.shirodemo.pojo.User;
import com.example.shirodemo.service.AdminService;
import com.example.shirodemo.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author 绫小路
 * @date 2021/1/10 18:29
 * @description
 */
@Api(tags = "00-公共页面，如主页、菜单获取：CommonController")
@Controller
public class CommonController {

  @Autowired
  private UserService userService;
  @Autowired
  private AdminService adminService;

  @ApiOperation("获取项目API")
  @GetMapping("api")
  @ResponseBody
  public ResponseResult api() {
    return adminService.getSwaggerApiList();
  }

  @ApiOperation("首页/主页页面")
  @GetMapping(value = {"", "index"})
  public String index() {
    return "index";
  }

  @ApiOperation("获取菜单列表")
  @GetMapping("/menu/get")
  @ResponseBody
  public ResponseResult get(HttpServletRequest request) {
    User user = (User) request.getSession().getAttribute("user");
    return new ResponseResult(HttpCode.OK, userService.getMenuList(user.getId()));
  }

}
